<?php
namespace Admin\Controller;
use Think\Controller;
class ClassifyController extends CommonController {

	public function level(){
		$M = M("Level");
		if(IS_POST){
			$act = I('post.act');
			if($act=='add'){
				$data = I('post.data');
				$data['name'] = trim($data['name']);
				$data['update_time'] = NOW_TIME;
				$data['create_time'] = NOW_TIME;
				$M->add($data);
				$this->ajaxReturn(array('status'=>1, 'info'=>'添加成功！', 'url'=>''));
			}
			if($act=="edit"){
				$id = I('post.id');
				$fd = I('post.fd');
				$value = I('post.value');
				$M->where( array('id'=>$id) )->setField($fd,$value);
			}
			if($act=='del'){
				$ids = I('post.id');
				$map['id'] = array('in',$ids);
				$M->where( $map )->delete();
		        $this->ajaxReturn(array('status'=>1, 'info'=>'成功删除！', 'url'=>''));
				exit;
			}
			exit;
		}

        $count = $M->where($map)->count();
        $Page       = new \Think\Page($count,25);
        $showPage = $Page->show();
        $this->assign("page", $showPage);

        $list = $M->where($map)->order('sort ASC, id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($list as $key => $val) {

        }
        $this->assign('list',$list);
		$this->display();
	}

	public function rank(){
		$M = M("Rank");
		if(IS_POST){
			$act = I('post.act');
			if($act=='add'){
				$data = I('post.data');
				$data['name'] = trim($data['name']);
				$data['update_time'] = NOW_TIME;
				$data['create_time'] = NOW_TIME;
				$M->add($data);
				$this->ajaxReturn(array('status'=>1, 'info'=>'添加成功！', 'url'=>''));
			}
			if($act=="edit"){
				$id = I('post.id');
				$fd = I('post.fd');
				$value = I('post.value');
				$M->where( array('id'=>$id) )->setField($fd,$value);
			}
			if($act=='del'){
				$ids = I('post.id');
				$map['id'] = array('in',$ids);
				$M->where( $map )->delete();
		        $this->ajaxReturn(array('status'=>1, 'info'=>'成功删除！', 'url'=>''));
				exit;
			}
			exit;
		}

        $count = $M->where($map)->count();
        $Page       = new \Think\Page($count,25);
        $showPage = $Page->show();
        $this->assign("page", $showPage);

        $list = $M->where($map)->order('sort ASC, id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($list as $key => $val) {

        }
        $this->assign('list',$list);

        $this->assign('column','详细级别');
		$this->display();
	}


}